package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.domain.ZhDeptInfo;
import com.ruoyi.common.service.IZhDeptInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhNav;
import com.ruoyi.system.service.IZhNavService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 导航栏 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-04-30
 */
@Controller
@RequestMapping("/system/zhNav")
public class ZhNavController extends BaseController
{
    private String prefix = "system/zhNav";
	
	@Autowired
	private IZhNavService zhNavService;
	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNav:view")
	@GetMapping()
	public String zhNav(ZhNav zhnav,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhnav.getParams())));
		return prefix + "/zhNav";
	}
	
	/**
	 * 查询导航栏列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNav:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhNav zhNav)
	{
		startPage();
        List<ZhNav> list = zhNavService.selectZhNavList(zhNav);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出导航栏列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNav:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhNav zhNav)
    {
    	List<ZhNav> list = zhNavService.selectZhNavList(zhNav);
        ExcelUtil<ZhNav> util = new ExcelUtil<ZhNav>(ZhNav.class);
        return util.exportExcel(list, "zhNav");
    }
	
	/**
	 * 新增导航栏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNav:add")
	@GetMapping("/add")
	public String add(ZhNav zhnav,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhnav.getParams())));

		return prefix + "/add";
	}
	
	/**
	 * 新增保存导航栏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNav:add")
	@Log(title = "导航栏", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhNav zhNav)
	{		
		return toAjax(zhNavService.insertZhNav(zhNav));
	}

	/**
	 * 修改导航栏
	 */
	@DataScope(tableAlias = "l")
	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:zhNav:edit")
	public String edit(ZhNav zhnav,@PathVariable("id") Integer id, ModelMap mmap)
	{

		ZhNav zhNav = zhNavService.selectZhNavById(id);
		mmap.put("zhNav", zhNav);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhnav.getParams())));

		return prefix + "/edit";
	}
	
	/**
	 * 修改保存导航栏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNav:edit")
	@Log(title = "导航栏", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhNav zhNav)
	{		
		return toAjax(zhNavService.updateZhNav(zhNav));
	}
	
	/**
	 * 删除导航栏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNav:remove")
	@Log(title = "导航栏", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhNav zhNav,String ids)
	{		
		return toAjax(zhNavService.deleteZhNavByIds(ids));
	}
	
}
